﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CheckOut : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoginUser();
         
        }
    }
    public void LoginUser()
    {
        if (Request.Cookies["LoginUser"] == null)
        {
            PanelDangNhap.Visible = true;
            PanelDonhang.Visible = false;
        }
        else
        {
            PanelDangNhap.Visible = false;
            PanelDonhang.Visible = true;
            txtHoTen.Text = Request.Cookies["LoginUser"]["HoTen"];
            txtDiaChi.Text = Request.Cookies["LoginUser"]["DiaChi"];
            txtEmail.Text = Request.Cookies["LoginUser"]["Email"];
            txtSDT.Text = Request.Cookies["LoginUser"]["SoDT"];
        }
    }
    dangnhap dnkh = new dangnhap();
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (dnkh.DangNhap(txtUser.Text, txtPass.Text) == true)
        {
            if (chkNhoMK.Checked)
            {
                Response.Cookies["LoginUser"]["KhachHangID"] = dnkh.KhachHangID.ToString();
                Response.Cookies["LoginUser"]["TenDangNhap"] = dnkh.TenDangNhap;
                Response.Cookies["LoginUser"]["MatKhau"] = dnkh.MatKhau;
                Response.Cookies["LoginUser"]["QuyenHan"] = dnkh.QuyenHan.ToString();
                Response.Cookies["LoginUser"]["HoTen"] = dnkh.HoTen;
                Response.Cookies["LoginUser"]["SoDT"] = dnkh.HoTen;
                Response.Cookies["LoginUser"]["DiaChi"] = dnkh.Diachi;
                Response.Cookies["LoginUser"]["Email"] = dnkh.Email;
                Response.Cookies["LoginUser"].Expires = DateTime.Now.AddDays(7);
                Response.Redirect("CheckOut.aspx");
            }
            else
            {
                Session["KhachHangID"] = dnkh.KhachHangID.ToString();
                Session["TenDangNhap"] = dnkh.TenDangNhap;
                Session["MatKhau"] = dnkh.MatKhau;
                Session["QuyenHan"] = dnkh.QuyenHan.ToString();
                Session["HoTen"] = dnkh.HoTen;
                Session["SoDT"] = dnkh.HoTen;
                Session["DiaChi"] = dnkh.Diachi;
                Session["Email"] = dnkh.Email;
                Response.Redirect("CheckOut.aspx");
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = "Tên đăng nhập hoặc mật khẩu sai";
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        HoaDon hd = new HoaDon();
        //hd.DaGiao = false;
        //hd.DiaChiNguoiNhan = txtDiaChi.Text;
        ////hd.KhachHangID = int.Parse(Request.Cookies["LoginUser"]["KhachHangID"]);
        //hd.KhachHangID = 1;
        //hd.HoTenNguoiNhan = txtHoTen.Text;
        //hd.SDTNguoiNhan = txtSDT.Text;
        //hd.Email = txtEmail.Text;
        //hd.TongTien = 0;

        hd.DaGiao = false;
        hd.DiaChiNguoiNhan = "adsad";
        //hd.KhachHangID = int.Parse(Request.Cookies["LoginUser"]["KhachHangID"]);
        hd.KhachHangID = 1;
        hd.HoTenNguoiNhan = "ads";
        hd.SDTNguoiNhan = "123";
        hd.Email ="3254235";
        hd.TongTien = 0;
        hd.Insert(hd);
        Response.Redirect("~/Deafault.aspx");
    }
    protected void btnHuyBo_Click(object sender, EventArgs e)
    {
        Response.Redirect("Deafault.aspx");
    }
}